/*
 * Created by SharpDevelop.
 * User: fatman
 * Date: 10/28/2008
 * Time: 3:08 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;

namespace CUALib
{
	/// <summary>
	/// Description of MenuPanelItem.
	/// </summary>
	public class MenuPanelItem : MenuItem
	{
		public MenuPanelItem(bool consoleExists)
			: base(consoleExists)
		{
		}
		public override void Invalidate(System.Drawing.Rectangle rect)
		{
			Redraw();
		}

		internal override void Redraw()
		{

			if (Parent == null)
				return;


			Point pp;
			int _indexParent;
			_indexParent = Parent.Controls.IndexOf(this);
			if (_indexParent == 0)
			{
				Location = Parent.Location;
				pp = Parent.Location;
			}
			else
			{
				Location = Parent.Controls [_indexParent - 1].Location;
				Rectangle abp = Parent.Controls [_indexParent - 1].AbsoluteBounds;
				pp = abp.Location;
				pp.Offset(0, 1);
			}

			Console.SetCursorPosition(pp.X, pp.Y);
			Console.Write(" " + Text + " ");


		}

		public override ConsoleControl Parent
		{
			get { return base.Parent; }
			set
			{
				if (!(value is MenuPanel))
					throw new Exception("Parent MUST be a MenuPanel instance");
				base.Parent = value;
				Parent.Height++;

			}
		}



		private string _text = string.Empty;
		public virtual string Text
		{
			get
			{
				return _text;
			}
			set
			{
				_text = value;
				Width = _text.Length + 2;
			}
		}



	}
}
